package org.springframework.samples.webflow.controller;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.webflow.dao.PersonDAO;
import org.springframework.samples.webflow.dto.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;





@Controller
public class HomeController {

	

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	@Autowired
	private PersonDAO personDAO;
	
	
	@RequestMapping(value = "/base", method = RequestMethod.GET)
	public String homePageHandler(Locale locale, HttpServletRequest request, Model model) {
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);

		String formattedDate = dateFormat.format(date);
		
		Person person = personDAO.getPersonById(1);
		logger.info("person:"+person.getFirstName());
		
		model.addAttribute("currentTime", formattedDate);
		return "base";
	}
	
	
	
	

}
